package org.example.loadbalancer;

import org.example.serializer.JdkSerializer;
import org.example.serializer.Serializer;
import org.example.spi.SpiLoader;

/**
 * 负载均衡器工厂(用于获取负载均衡器对象)
 */
public class LoadBalancerFactory {

    static {
        SpiLoader.load(LoadBalancer.class);
    }

    /**
     * 默认负载均衡器
     */
    private static final LoadBalancer DEFAULT_LOAD_BALANCER = new RoundRobinLoadBalancer();

    /**
     * 获取实例
     * @param key
     * @return
     */
    public static LoadBalancer getInstance(String key) {
        System.out.println(Thread.currentThread().getName() + "执行LoadBalancerFactory中的getInstance(key)方法" + "参数为：" + key);

        return SpiLoader.getInstance(LoadBalancer.class,key);
    }
}
